package com.huanghuai.retail.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanghuai.retail.common.R;
import com.huanghuai.retail.entity.DeviceType;
import com.huanghuai.retail.service.DeviceTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deviceType")
@Slf4j
public class DeviceTypeController {
    @Resource
    private DeviceTypeService deviceTypeService;
    @PostMapping
    public R<String> saves(@RequestBody DeviceType deviceType){
        return deviceTypeService.saves(deviceType);
    }
    @PutMapping
    public R<String> updates(@RequestBody DeviceType deviceType) {
        return deviceTypeService.updates(deviceType);
    }
    @DeleteMapping("/{id}")
    @Transactional
    public R<String> deletes(@PathVariable("id") Long id) {
        return deviceTypeService.deletes(id);
    }
    @GetMapping("/{id}")
    public R<DeviceType> getByIds(@PathVariable("id") Long id) {
        return deviceTypeService.getByIds(id);
    }
    @GetMapping("/page")
    public R<Page<DeviceType>> pages(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "5") int pageSize,
                                    @RequestParam(defaultValue = "") String name) {
       return deviceTypeService.pages(page, pageSize, name);
    }
}
